package com.szholly.pro.watergas_server.ps.controller;



import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import com.szholly.pro.watergas_server.common.data.DataUtil;
import com.szholly.pro.watergas_server.common.web.BaseController;
import com.szholly.pro.watergas_server.common.web.RequestUnit;
import com.szholly.pro.watergas_server.ps.service.BlindSampleService;
import com.szholly.utils.spring.SpringBeanFactory;
import com.szholly.data.general.ITable;
import com.szholly.data.general.ITableFactory;
import com.szholly.data.general.PageInfo;
import com.szholly.data.general.RowBase;
import com.szholly.plug.form.excel.utils.StringUtil;


import net.sf.json.JSONObject;

/**
 * 盲样与抽测
 * @author wzj
 *
 */
@Controller
@RequestMapping("/blindSampleController/*")
public class BlindSampleController extends BaseController{

	@Autowired
	BlindSampleService blindSampleService;
	
	/**
	 * 获取在线数据比对
	 * @param resq
	 * @param res
	 */
	@RequestMapping("/queryBlindSample")
	public void queryWaterThan(HttpServletRequest resq, HttpServletResponse res)throws Exception{		 		 
		Map<String,String> params=queryStationQueryParams();
		ITableFactory tableFactory = (ITableFactory) SpringBeanFactory.getBean("TableFactory");
		ITable pTable = tableFactory.openTable("QC_WATER_THAN");		
		PageInfo pageInfo = DataUtil.getPageInfo();
		List<RowBase> blindSampledata=blindSampleService.queryBlindSample(params,pTable,pageInfo);
		JSONObject JSON=DataUtil.listToJSONObject(blindSampledata, null, pageInfo);
		outString(JSON.toString());
	}
	/**
	 * 盲样与抽测excel
	 * @param resq
	 * @param res
	 * @throws Exception
	 */
	@RequestMapping("/outBlindSample")
	public void outBlindSample(HttpServletRequest resq, HttpServletResponse res)throws Exception{
		Map<String,String> params=queryStationQueryParams();
		List<RowBase> blindSampledata=blindSampleService.outBlindSample(params,null,null);
		System.out.println("记录数======="+blindSampledata.size());
		HashMap<String,Object> data=new HashMap<>();
		data.put("blindSampledata", blindSampledata);
		data.put("start", params.get("start"));
		data.put("end", params.get("end"));
		HtmlToExcel(data, "qc/blindSample.html", "盲样与抽测.xls");
	}
	/**
	 * 根据公司编号，获取参数信息
	 * @param resq
	 * @param res
	 */
	@RequestMapping("/getCompanyParam")
	public void getCompanyParam(HttpServletRequest resq, HttpServletResponse res)throws Exception{
		Map<String,String> params=queryStationQueryParams();
		List<RowBase> companyParamdata=blindSampleService.getCompanyParam(params);
		JSONObject JSON=DataUtil.listToJSONObject(companyParamdata, null, null);
		outString(JSON.toString());
	}
	/**
	 * 根据公司编号，获取监测类型
	 * @param resq
	 * @param res
	 */
	@RequestMapping("/getMonitorType")
	public void getMonitorType(HttpServletRequest resq, HttpServletResponse res)throws Exception{
		Map<String,String> params=queryStationQueryParams();
		List<RowBase> MonitorType=blindSampleService.getMonitorType(params);
		JSONObject JSON=DataUtil.listToJSONObject(MonitorType, null, null);
		outString(JSON.toString());
	}
	private Map<String,String> queryStationQueryParams() {
		Map<String,String> params = new HashMap<>();
		String stationid=RequestUnit.getString("STATION_ID");
		String start=RequestUnit.getString("start");
		String CompanyId=RequestUnit.getString("CompanyId");
		String end=RequestUnit.getString("end");
		String thanType=RequestUnit.getString("thanType");
		String companyCount=RequestUnit.getString("companyCount");
		String moniitorType=RequestUnit.getString("moniitorType");
		params.put("stationid", stationid);
		if(StringUtil.IsNotNullOrEmpty(thanType)){
			if(thanType.equals("'all'")){
				params.put("thanType", "'1','2'");
			}else{
				params.put("thanType", thanType);
			}
		}		
		params.put("moniitorType", moniitorType);
		params.put("end", end);
		params.put("COMPANYID", CompanyId);
		params.put("COMPANYCOUNT", companyCount);
		params.put("start", start);
		return params;
	}
}
